// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import GlobaConfig from "./GlobaConfig";
import ShelfCell from "./ShelfCell";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Shelf extends cc.Component {

    @property(cc.Prefab) shelf_cell: cc.Prefab = null;

    jsonAsset;
    shelfNumber: number; // 货架编号

    init(jsonAsset, shelfNumber) {
        this.jsonAsset = jsonAsset
        this.shelfNumber = shelfNumber;
        this.creatorShelfCell()
    }

    // 创建货架层级
    creatorShelfCell(){
        for (let i = 0; i < this.jsonAsset.shelf_cell_num; i++) {
            const element = cc.instantiate(this.shelf_cell);
            element.getComponent(ShelfCell).init(this.shelfNumber, i)
            this.node.addChild(element)
            element.width = this.jsonAsset.shelf_width * GlobaConfig.Pixels;
            element.height = this.jsonAsset.shelf_high_per_cell * GlobaConfig.Pixels;
            GlobaConfig.AllShelfCell[this.shelfNumber].push(element)
        }
    }

    // update (dt) {}
}
